package JDBC;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class testJdbcTemplate {
    @Test
    public void testCreate(){
        //初始化spring容器，加载jdbc-context.xml配置
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("jdbc-context.xml");
        //通过容器获取JdbcTemplate的实例
        JdbcTemplate jdbcTemplate = (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
        //使用execute()方法执行SQL语句
        jdbcTemplate.execute("create table account(" +
                "id int primary key auto_increment," +
                "username varchar(50)," +
                "balance double)");
        System.out.println("账户表account创建成功！");
    }
}
